<?php

namespace handle\message\lib\socket;

use Workerman\Connection\TcpConnection;

class SocketHandler
{
    private TcpConnection $connection;

    public function __construct(TcpConnection $connection){
        $this->connection = $connection;
    }

    /**
     * 发送提示消息
     * @param string $msg          提示消息
     * @param string $msgType      提示类型
     * @return void
     */
    public function sendMsg(string $msg, string $msgType = 'warning', array $msgData = []){
        $this->connection->lastSendTime = time();
        $this->connection->send(sendMsg($msg, $msgType, $msgData)); //发送提示信息
    }

    /**
     * 发送类型消息
     * @param string $type          消息类型
     * @param array $mainInfo       主体消息
     * @return void
     */
    public function sendData(string $type, array $mainInfo = []){
        $this->connection->lastSendTime = time();
        $this->connection->send(sendData($type, $mainInfo)); //发送消息
    }

    /**
     * 如果当前类没有xx方法，调用底层类
     * @return void
     */
    public function __call($name, $arguments){
        return call_user_func_array([$this->connection, $name], $arguments);
    }
}